(defvar plugin-home-dir (concat (getenv "HOME") ".emacs.d/plugins/"))

(add-to-list 'load-path (concat plugin-home-dir "benchmark-init-el"))
(let (
      (gc-cons-threshold most-positive-fixnum)
      (file-name-handler-alist nil))
      (require 'benchmark-init-modes)
      (require 'benchmark-init)
      (benchmark-init/activate)

      ;; M-x benchmark-init/show-durations-tree
      ;; 下面才写你的其它配置
      ;;M-x describe-variable, 快捷键 C-h v, 查看变量的文档
      ;;M-x describe-function, 快捷键 C-h f, 查看命令的文档
      ;;M-x describe-key, 快捷键 C-h k, 查看快捷键的文档
      ;;M-x emacs-version
      ;;emacs --version
  
      ;(add-to-list 'load-path (expand-file-name "~/elisp"))
      ;(require 'lazy-load)
      ;(lazy-load-global-keys
      ; '(("M-g" . goto-line-preview))
      ; "goto-line-preview")
  
  
    ;    (add-to-list 'load-path (concat plugin-home-dir "meghanada"))
    ;    (require 'meghanada)
    ;    (add-hook 'java-mode-hook
    ;        (lambda ()
    ;            ;; meghanada-mode on
    ;            (meghanada-mode t)
    ;            (flycheck-mode +1)
    ;            (setq c-basic-offset 2)
    ;            ;; use code format
    ;            (add-hook 'before-save-hook 'meghanada-code-beautify-before-save))
    ;    )
    ;    (cond
    ;        ((eq system-type 'windows-nt)
    ;            (setq meghanada-java-path (expand-file-name "bin/java.exe" (getenv "JAVA_HOME")))
    ;            (setq meghanada-maven-path "mvn.cmd")
    ;        )
    ;    )
    



      (add-to-list 'load-path (concat plugin-home-dir "uuid"))
      (require 'uuid)
  
      (add-to-list 'load-path (concat plugin-home-dir "citre"))
      (require 'citre)
      (require 'citre-config)

      ;session
      (add-to-list 'load-path (concat plugin-home-dir "session-2.4b"))
      (require 'session)
      ;; session will be save if a buffer is save to a file.
      (add-hook 'after-save-hook 'session-save-session)
      (add-hook 'after-init-hook 'session-initialize)
      (session-initialize)
      (session-jump-to-last-change)
	  (desktop-save-mode t)

  
  
      ; swiper.el
      (add-to-list 'load-path (concat plugin-home-dir "swiper.el"))
      (require 'swiper)
      (require 'counsel)
  
      
      ; undotree.el
      ;(add-to-list 'load-path (concat plugin-home-dir "undo-tree.el"))
      ;(require 'undo-tree)
      ;(global-undo-tree-mode)
      
      ; vundo.el
      (add-to-list 'load-path (concat plugin-home-dir "vundo.el"))
      (require 'vundo)
      (setq vundo-glyph-alist vundo-unicode-symbols)
      (set-face-attribute 'vundo-default nil :family "Symbola")
      
      (global-set-key (kbd "C-x u") 'vundo)
  
      
      
      ; company.el
      (add-to-list 'load-path (concat plugin-home-dir "company.el"))
      (require 'company)
      (global-company-mode)
  
      ; auto-dim-other-buffers.el
      (add-to-list 'load-path (concat plugin-home-dir "auto-dim-other-buffers.el"))
      (require 'auto-dim-other-buffers)
      (auto-dim-other-buffers-mode)
  
      
      ;(add-to-list 'load-path (concat plugin-home-dir "magit.plugin/dash-2.19.1"))
      ;;(add-to-list 'load-path (concat plugin-home-dir "magit.plugin/git-commit-3.3.0"))
      ;;(add-to-list 'load-path (concat plugin-home-dir "magit.plugin/transient-0.3.7"))
      ;;(add-to-list 'load-path (concat plugin-home-dir "magit.plugin/with-editor-3.2.0"))
      ;;(add-to-list 'load-path (concat plugin-home-dir "magit.plugin/magit-section-3.3.0"))
      ;;(add-to-list 'load-path (concat plugin-home-dir "magit.plugin/magit-3.3.0"))
      ;(require 'dash)
      ;;(require 'with-editor)
      ;;(require 'transient)
      ;;(require 'magit)
      ;; M-x list-packages, find magit (use C-s to search just like any other buffer). With the cursor on the Magit line, type i to mark the package for installation, then x to execute. It will install Magit plus all of its dependencies automatically.
      ;(global-set-key (kbd "C-x g") 'magit)
  
      ; evil
      (add-to-list 'load-path (concat plugin-home-dir "evil-1.15.0"))
      (require 'evil)
      (evil-mode 1)
      
  
      ; org.el
      ;(add-to-list 'load-path (concat plugin-home-dir "org.el"))
      ;(require 'org)
      ;; The following lines are always needed. Choose your own keys.
      ;(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode))
      ;(add-hook 'org-mode-hook 'turn-on-font-lock) ; not needed when global-font-lock-mode is on
      ;(global-set-key "\C-cl" 'org-store-link)
      ;(global-set-key "\C-ca" 'org-agenda)
      ;(global-set-key "\C-cb" 'org-iswitchb)
      
      
  ;    (add-to-list 'load-path (concat plugin-home-dir "color-theme-6.6.0"))
  ;    (require 'color-theme)
  ;    (eval-after-load "color-theme"
  ;    '(progn
  ;        (color-theme-initialize)
  ;        (color-theme-hober)))
  
      (add-to-list 'load-path (concat plugin-home-dir "tic80-mode"))
      (require 'tic80)
  	
      (add-to-list 'custom-theme-load-path (concat plugin-home-dir "theme-molokai"))
      (load-theme 'molokai t)
  
      (add-to-list 'custom-theme-load-path (concat plugin-home-dir "theme-monokai-3.5.3"))
      (load-theme 'monokai t)
  	
      (add-to-list 'custom-theme-load-path (concat plugin-home-dir "theme-dracula"))
      (load-theme 'dracula t)
   
  
      (add-to-list 'custom-theme-load-path (concat plugin-home-dir "theme-atom-dark"))
      (load-theme 'atom-dark t)
      (add-to-list 'custom-theme-load-path (concat plugin-home-dir "theme-atom-one-dark"))
      (load-theme 'atom-one-dark t)
      (add-to-list 'custom-theme-load-path (concat plugin-home-dir "theme-darkokai"))
      (load-theme 'darkokai t)
  
  	
  
  
      (setenv "PATH" (concat "C:/Program Files/Git/bin" ";"(getenv "PATH")))
      ;(setq default-directory "E:/homefile/")
      ;(setq command-line-default-directory "E:/homefile/")
      
      
      
      ; C:CTRL
      ; M:Meta,往往是ALT(部分键盘是ESC)
      
      ; M-x menu-bar-mode
      ; M-x linum-mode
      ; M-x global-linum-mode
      ; M-x global-display-line-numbers-mode
      ; M-x display-line-numbers-mode
      
      ; 第一，执行 C-x u 向后撤销;
      ; 第二，执行 C-g 然后 C-x u 就是向前撤销了
      ; emacs --version
      ; M-x emacs-version
      
      ; C-n，下一行（速记：Nextline）
      ; C-p，前一行（速记：Previous line）
      ; C-f，向前移动一个字符（速记：Forward）
      ; C-b，向后退一个字符（速记：Backforward）
      ; C-k，从光标位置到末尾删掉（速记：Kill）
      ; C-a，回到行首（速记：a是字母表的开始）
      ; C-e，去往行尾（速记：End of line）
      ; M - <，回到编辑区域最开始位置（速记：<）
      ; M - >，去往编辑区域最后的位置（速记：>）
      ; C-v，向下翻一屏
      ; M-v，向上翻一屏
      
      (setq make-backup-files nil)
  
      ;;;;;;;;;;;;;;;;;;;;;;;;;
      ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
      ;; theme
      ;(load-theme 'atom-one-dark t)
      ;(load-theme 'wombat)
      ;(custom-theme-set-faces
      ; 'wombat
      ; '(cursor ((t (:background "#abb2bf")))))
      ;(enable-theme 'wombat)
      ;manoj-dark
      ;modus-vivendi
      ;wheatgrass
      ;wombat

      
   
  
      (global-set-key [f8] 'neotree-toggle)
      (setq neo-smart-open t)
      
      
      ; C-u8C-n
      ; C-u80*
  
      
  
      ;----------
      ; M-x restclient-mode
      ; qry.http
      ; GET https://api.github.com
      ; User-Agent: Emacs Restclient
      ; C-c C-c: runs the query under the cursor, tries to pretty-print the response (if possible)
      ; C-c C-r: same, but does not do anything with the response, just shows the buffer
      ; C-c C-v: same as C-c C-c, but doesn’t switch focus to other window
      ;----------
      ; C-x d
      ; C-x C-f
      ; C-x C-j
      ; M-x dired
      ;----------
      ; C-x C-c
      ; C-g
      ;------
      ; C-z
      ; fg:Foreground
      ;------
      ; C-p C-n C-b C-f
      ; previous, next, back, forward
      ; M-b M-f
      ; C-a C-e; M-m
      ; M-a M-e
      ; M-< M->
      ;-------------------------
      ; adjust current line
      ; M-r; C-l 
      ;-------------------------
      ; mark and go back
      ; C-S-SPC
      ; C-u C-S-SPC
      ;-------------------------
      
      
      ;;; ---- 执行了一个函数启动 ivy mode ----
      (ivy-mode 1)
      ;;; ---- 设置两个变量为 True，还有一个可选的 ---
      ;(setq ivy-use-virtual-buffers t)
      ;(setq enable-recursive-minibuffers t)
      ;;; enable this if you want `swiper' to use it
      ;(setq search-default-mode #'char-fold-to-regexp)
      ;;; ---- 绑定快捷键 ----
      ;(global-set-key "\C-s" 'swiper)
      ;(global-set-key (kbd "C-c C-r") 'ivy-resume)
      ;(global-set-key (kbd "<f6>") 'ivy-resume)
      ;(global-set-key (kbd "M-x") 'counsel-M-x)
      ;(global-set-key (kbd "C-x C-f") 'counsel-find-file)
      ;(global-set-key (kbd "<f1> f") 'counsel-describe-function)
      ;(global-set-key (kbd "<f1> v") 'counsel-describe-variable)
      ;(global-set-key (kbd "<f1> o") 'counsel-describe-symbol)
      ;(global-set-key (kbd "<f1> l") 'counsel-find-library)
      ;(global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol)
      ;(global-set-key (kbd "<f2> u") 'counsel-unicode-char)
      ;(global-set-key (kbd "C-c g") 'counsel-git)
      ;(global-set-key (kbd "C-c j") 'counsel-git-grep)
      ;(global-set-key (kbd "C-c k") 'counsel-ag)
      ;(global-set-key (kbd "C-x l") 'counsel-locate)
      ;(global-set-key (kbd "C-S-o") 'counsel-rhythmbox)
      ;(define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history)
      
      (define-key global-map [C-return] 'set-mark-command)
      
      (setq undo-tree-auto-save-history nil)
      (setq undo-tree-history-directory-alist '(("." . "~/.emacs.d/.cache/")))
      
      (defun hello3 ()
        "在windows中用explorer浏览当前目录"
        (interactive)
        (shell-command "explorer.exe .")
        (browse-url "www.baidu.cn")
        )
      
      (defun hello2 ()
        "执行shell命令并处理它的输出。这里为显示当前目录下的文件"
        (interactive)
        (message (shell-command-to-string "ls -l"))
        )
      
      
      (defun hello1 ()       ; Interactive version.
        "Multiply NUMBER by seven."
        (interactive)
        (message (format-time-string "%Y-%m-%d %H:%M:%S" (current-time))))
      
      
      (require 'midnight)
      (midnight-delay-set 'midnight-delay 17000) ;; (eq (* 4.5 60 60) "4:30am")
      (setq midnight-period 2) ;; (eq (* 2 60 60) "2 hours")
      (add-hook 'midnight-hook 'hello)
  
      
      (add-to-list 'load-path (concat plugin-home-dir "neotree"))
      (require 'neotree)
      (global-set-key [f8] 'neotree-toggle)
  
   
  
      (add-to-list 'load-path (concat plugin-home-dir "dash-2.19.1"))
      (require 'dash)
      (add-to-list 'load-path (concat plugin-home-dir "epl-0.9"))
      (require 'epl)
      (add-to-list 'load-path (concat plugin-home-dir "flycheck-32"))
      (require 'flycheck)
      (add-to-list 'load-path (concat plugin-home-dir "pkg-info-0.6"))
      (require 'pkg-info)
  
  
      
      (add-to-list 'load-path (concat plugin-home-dir "winum"))
      (require 'winum)
      (winum-mode)
      (setq winum-keymap
          (let ((map (make-sparse-keymap)))
            (define-key map (kbd "C-`") 'winum-select-window-by-number)
            (define-key map (kbd "C-2") 'winum-select-window-by-number)
            (define-key map (kbd "M-0") 'winum-select-window-0-or-10)
            (define-key map (kbd "M-1") 'winum-select-window-1)
            (define-key map (kbd "M-2") 'winum-select-window-2)
            (define-key map (kbd "M-3") 'winum-select-window-3)
            (define-key map (kbd "M-4") 'winum-select-window-4)
            (define-key map (kbd "M-5") 'winum-select-window-5)
            (define-key map (kbd "M-6") 'winum-select-window-6)
            (define-key map (kbd "M-7") 'winum-select-window-7)
            (define-key map (kbd "M-8") 'winum-select-window-8)
            map))
  
      (add-to-list 'load-path (concat plugin-home-dir "evil-leader"))
      (require 'evil-leader)
      (global-evil-leader-mode)
      (evil-leader/set-key
        "n" (let ((map (make-sparse-keymap)))
            (define-key map (kbd "t") 'nav-toggle)
            map)
        "c" 'tab-close
        "t" 'tab-bar-switch-tab
        "od" 'dired
        "ee" 'eval-this-buffer
        "fp" 'find-file-in-project
	"fd" 'projectile-find-file-in-directory
        "ff" 'helm-find-files
        "fh" 'helm-find-files-history
        "fa" 'counsel-buffer-or-recentf
        "fr" 'recentf-open-files
        "br" 'revert-buffer-quick
        "bli" 'ibuffer-list-buffers
        "blr" 'helm-resume-list-buffers-after-quit
        "blh" 'helm-buffers-list
        "bll" 'list-buffers
        "blc" 'counsel-ibuffer
        "TAB" 'evil-buffer
        "bb" 'switch-to-buffer
        "bw" 'save-buffer
        "baga" 'helm-do-ag-buffers
        "bagb" 'helm-ag-buffers
        "bp" 'c-switch-to-next-buffer  ;;previous-buffer
        "bn" 'c-switch-to-prev-buffer  ;;next-buffer
        "bv" 'view-buffer
        "bd" 'display-buffer
        "bkk" 'kill-buffer
        "bkc" 'kill-this-buffer
        "bks" 'kill-some-buffers
        "bkm" 'kill-matching-buffers
        "bkw" 'kill-buffer-and-window
        "bsw" 'helm-swoop
        "bss" 'helm-multi-swoop
        "yl" 'yas-reload-all
        "yn" 'yas-new-snippet
        "yi" 'yas-insert-snippet
        "ye" 'yas-expand-from-trigger-key
        "rf" 'counsel-recentf
        "ss" 'swiper
        "savy" 'swiper-avy
        "sall" 'swiper-all
        "sis" 'swiper-isearch
        "sapa" 'swiper-all-thingh-at-point
        "sapb" 'swiper-thing-at-point
        "ag" 'helm-ag
        "rg" 'helm-rg
        "so" 'helm-occur
        "run" 'eval-last-sexp
        "0" 'winum-select-window-0
        "1" 'winum-select-window-1
        "2" 'winum-select-window-2
        "3" 'winum-select-window-3
        "4" 'winum-select-window-4
        "5" 'winum-select-window-5
        "6" 'winum-select-window-6
        "7" 'winum-select-window-7
        "8" 'winum-select-window-8
        "jp" 'ace-pinyin-dwim
        "jj" 'evil-avy-goto-char-timer
        "mes" 'evil-set-marker
        "meg" 'evil-goto-mark
        "ms" 'bookmark-set
        "mg" 'bookmark-jump
        "md" 'bookmark-delete
        "mc" 'bookmark-delete-all
        "rv" 'counsel-evil-jegisters
        "na" 'menu-bar--display-line-numbers-mode-absolute
        "nr" 'menu-bar--display-line-numbers-mode-relative
        "nn" 'display-line-numbers-mode
        "nv" 'menu-bar--display-line-numbers-mode-visual
        "nu" 'menu-bar--display-line-numbers-mode-none
        "nw" 'menu-bar--wrap-long-lines-window-edge
        "nt"  'menu-bar--toggle-truncate-long-lines
        "law" 'persp-add-new
        "lab" 'persp-add-buffer
        "lsf" 'persp-frame-switch
        "lsw" 'persp-window-switch
        "lsb" 'persp-switch-to-buffer
        "lcp" 'persp-copy
        "lj" 'persp-prev
        "lk" 'persp-next
        "ll" 'persp-switch
        "lL" 'persp-load-state-from-file
        "ls" 'persp-save-state-to-file
        "pp" 'projectile-switch-project
        "pss" 'project-search
        "ptb" 'project-switch-to-buffer
        "ptp" 'project-switch-project
        "pff" 'projectile-find-file
        "vm" 'counsel-minor
        "wm" 'toggle-maximize-buffer
        "ww" 'ace-window
        "wv" 'evil-window-vsplit
        "ws" 'evil-window-new
        "wl" 'evil-window-right
        "wh" 'evil-window-left
        "wk" 'evil-window-up
        "wj" 'evil-window-down
        "wo" 'other-window
        "wnl" 'split-window-right
        "wnj" 'split-window-below
  
        "http2" 'restclient-http-send-current
        "http1" 'restclient-http-send-current-raw
        "http0" 'restclient-http-send-current-stay-in-window
        "uuid" 'uuid-insert
        "newline" 'new-line
  
        "lisp" 'eval-this-buffer
        ","  'eshell
        ":"  'commandp
        "x"  'execute-extended-command
        "<SPC>"  'isearch-cancel
        "wM" 'delete-other-windows)
      (evil-leader/set-leader "<SPC>")
      ;;(evil-leader/set-key-for-mode 'emacs-lisp-mode "b" 'byte-compile-file)
      
      ;;(menu-bar--visual-line-mode-enable t)
  
  
      (add-to-list 'load-path (concat plugin-home-dir "wgrep"))
      (require 'wgrep)
  
      (add-to-list 'load-path (concat plugin-home-dir "rg.el"))
      (require 'rg)
  
  
      (add-to-list 'load-path (concat plugin-home-dir "projectile"))
      (require 'projectile)
      (projectile-global-mode)
      (setq projectile-enable-caching t)
      (setq projectile-mode-line "Projectile") 
      (global-set-key [f5] 'projectile-find-file)
  
      
      (add-to-list 'load-path (concat plugin-home-dir "avy"))
      (require 'avy)
      
      (add-to-list 'load-path (concat plugin-home-dir "ace-window"))
      (require 'ace-window)
      
      (add-to-list 'load-path (concat plugin-home-dir "hydra"))
      (require 'hydra)
  
      
      
      
      
  
      
      
      (add-to-list 'load-path (concat plugin-home-dir "yasnippet"))
      (require 'yasnippet)
      (yas-global-mode 1)
      (yas-minor-mode 1)
      ;;M-x yas-minor-mode
      (yas-reload-all)
      (add-hook 'prog-mode-hook #'yas-minor-mode)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "ace-jump-buffer"))
      (require 'ace-jump-buffer)
      
      ;;(add-to-list 'load-path (concat plugin-home-dir "ace-jump-zap"))
      ;;(require 'ace-jump-zap)
      ;;(ace-pinyin-mode 1)
      ;;(ace-jump-char-mode 1)
      
      
      ;;
      ;; ace jump mode major function
      ;; 
      (add-to-list 'load-path (concat plugin-home-dir "ace-jump-mode"))
      (require 'ace-jump-mode)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "ace-pinyin"))
      (require 'ace-pinyin)
      
      
      
      (add-to-list 'load-path (concat plugin-home-dir "emacs-which-key"))
      (require 'which-key)
      (which-key-mode)
      
      
      
      (add-to-list 'load-path (concat plugin-home-dir "minibuffer-modifier-keys"))
      (require 'minibuffer-modifier-keys)
      ;; init
      (minibuffer-modifier-keys-setup t)
      
      
      ;;(add-to-list 'load-path (concat plugin-home-dir "popper"))
      ;;(require 'popper)
      ;;(setq popper-reference-buffers
      ;;      '("\\*Messages\\*"
      ;;        "Output\\*$"
      ;;        "\\*Async Shell Command\\*"
      ;;        help-mode
      ;;        compilation-mode))
      ;;(global-set-key (kbd "C-`") 'popper-toggle-latest)  
      ;;(global-set-key (kbd "M-`") 'popper-cycle)
      ;;(global-set-key (kbd "C-M-`") 'popper-toggle-type)
      ;;(popper-mode +1)
      
      ;; For echo-area hints
      ;;(require 'popper-echo)
      ;;(popper-echo-mode +1)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "popup"))
      (require 'popup)
      (setq popup (popup-create (point) 10 10))
      (popup-set-list popup '("Foo" "Bar" "Baz"))
      (popup-draw popup)
      ;; do something here
      (popup-delete popup)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "popwin"))
      (require 'popwin)
      (popwin-mode 1)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "ivy-0.14.0"))
      (require 'ivy)
  
      
      
      (add-to-list 'load-path (concat plugin-home-dir "autopair"))
      (require 'autopair)
      (autopair-global-mode) ;; enable autopair in all buffers
      
      
  
      (add-to-list 'load-path (concat plugin-home-dir "posframe"))
      (require 'posframe)
  ;;    (when (posframe-workable-p)
  ;;      (posframe-show " *my-posframe-buffer*"
  ;;                     :string "This is a test"
  ;;                    :position (point)))
  
      
      
      (add-to-list 'load-path (concat plugin-home-dir "persp-mode-20230110.1045"))
      (require 'persp-mode)
      (persp-mode 1)
      (setq enable-local-variables nil)
      
      (add-to-list 'load-path (concat plugin-home-dir "ivy-posframe"))
      (require 'ivy-posframe)
      ;; Different command can use different display function.
      ;;(setq ivy-posframe-height-alist '((swiper . 20)
      ;;                                  (t      . 40)))
      ;;(setq ivy-posframe-display-functions-alist
      ;;      '((swiper          . ivy-display-function-fallback)
      ;;        (complete-symbol . ivy-posframe-display-at-point)
      ;;        (counsel-M-x     . ivy-posframe-display-at-window-bottom-left)
      ;;        (t               . ivy-posframe-display)))
     (ivy-posframe-mode 1)
      
      
  
  
      
      
      (add-to-list 'load-path (concat plugin-home-dir "s-20220902.1511"))
      (require 's)
      (add-to-list 'load-path (concat plugin-home-dir "f-20230116.1032"))
      (require 'f)
      
      (add-to-list 'load-path (concat plugin-home-dir "ht-20230214.1632"))
      (require 'ht)
  	
  	
      (add-to-list 'load-path (concat plugin-home-dir "async"))
      (require 'async)
  
      (add-to-list 'load-path (concat plugin-home-dir "haml-mode-20230608.1833"))
      (require 'haml-mode)
  
      
      
      (add-to-list 'load-path (concat plugin-home-dir "helm"))
      (require 'helm)
      (require 'helm-files)
      (setq helm-echo-input-in-header-line t)
      
      (add-to-list 'load-path (concat plugin-home-dir "helm-core-20230616.936"))
      (require 'helm-core)
      
      (add-to-list 'load-path (concat plugin-home-dir "helm-swoop-20210426.547"))
      (require 'helm-swoop)
  
      (add-to-list 'load-path (concat plugin-home-dir "helm-ag"))
      (require 'helm-ag)
  
      (add-to-list 'load-path (concat plugin-home-dir "helm-rg"))
      (require 'helm-rg)
      
  
      (add-to-list 'load-path (concat plugin-home-dir "find-file-in-project"))
      (require 'find-file-in-project)
      (setq ffip-prefer-ido-mode t)
      (ivy-mode 1)
  ;;    (helm-mode 1)
  
      
      (add-to-list 'load-path (concat plugin-home-dir "markdown-mode-20230607.320"))
      (require 'markdown-mode)
      (add-to-list 'load-path (concat plugin-home-dir "markdown-toc-20210905.738"))
      (require 'markdown-toc)
      
      (add-to-list 'load-path (concat plugin-home-dir "spinner-1.7.4"))
      (require 'spinner)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "window-purpose-20210628.715"))
      (require 'window-purpose)
      
      
      (add-to-list 'load-path (concat plugin-home-dir "lsp-mode-20230614.2208"))
      (require 'lsp-mode)
      (add-to-list 'load-path (concat plugin-home-dir "lsp-ui-20230116.2024"))
      (require 'lsp-ui)
  
  	;;(add-to-list 'load-path (concat plugin-home-dir "slim"))
      ;;(require 'slim)
  
  	;(add-to-list 'load-path (concat plugin-home-dir "slim-mode-20170728.1348"))
      ;(require 'slim-mode)
  	;(slim-mode t)
  
  
  
  
  	(add-to-list 'load-path (concat plugin-home-dir "simple-httpd-20191103.1446"))
      (require 'simple-httpd)
      ;;(setq httpd-root (concat (getenv "HOME") "www/html/"))
      ;;(httpd-start)
  
  	(add-to-list 'load-path (concat plugin-home-dir "htmlize"))
      (require 'htmlize)
  
  	(add-to-list 'load-path (concat plugin-home-dir "impatient-mode"))
      (require 'impatient-mode)
  
  
  
      (add-to-list 'load-path (concat plugin-home-dir "helm-ag-20221017.1528"))
      (require 'helm-ag)
      (add-to-list 'load-path (concat plugin-home-dir "helm-company-20190812.1429"))
      (require 'helm-company)
      (add-to-list 'load-path (concat plugin-home-dir "helm-css-scss-20230522.1113"))
      (require 'helm-css-scss)
      (add-to-list 'load-path (concat plugin-home-dir "helm-c-yasnippet-20210330.16"))
      (require 'helm-c-yasnippet)
      (add-to-list 'load-path (concat plugin-home-dir "helm-descbinds-20190501.935"))
      (require 'helm-descbinds)
      (add-to-list 'load-path (concat plugin-home-dir "helm-git-grep-20170614.1411"))
      (require 'helm-git-grep)
      (add-to-list 'load-path (concat plugin-home-dir "helm-ls-git-20230505.1437"))
      (require 'helm-ls-git)
      (add-to-list 'load-path (concat plugin-home-dir "helm-lsp-20210419.2014"))
      (require 'helm-lsp)
      (add-to-list 'load-path (concat plugin-home-dir "helm-mode-manager-20210108.2330"))
      (require 'helm-mode-manager)
      (add-to-list 'load-path (concat plugin-home-dir "helm-org-20210324.1927"))
      (require 'helm-org)
      (add-to-list 'load-path (concat plugin-home-dir "helm-org-rifle-20221024.1943"))
      (require 'helm-org-rifle)
      (add-to-list 'load-path (concat plugin-home-dir "helm-projectile-20221215.613"))
      (require 'helm-projectile)
      (add-to-list 'load-path (concat plugin-home-dir "helm-purpose-20170114.1636"))
      (require 'helm-purpose)
      (add-to-list 'load-path (concat plugin-home-dir "helm-themes-20220721.330"))
      (require 'helm-themes)
      (add-to-list 'load-path (concat plugin-home-dir "helm-xref-20211017.1334"))
      (require 'helm-xref)
  
  
  
  
      ;;(add-to-list 'load-path (concat plugin-home-dir "perspeen"))
      ;;(require 'perspeen)
      ;;(setq perspeen-use-tab t)
      ;;(perspeen-mode 1)
  
  
  	; restclient
      (add-to-list 'load-path (concat plugin-home-dir "restclient.el"))
      (require 'restclient)
  	(require 'restclient-helm)
  
  
      ;(defun http-send-times (&optional count)
      ;  (interactive "p")
      ;  (if (null count)
      ;      (restclient-http-send-current-stay-in-window)
      ;    (dotimes (_ count) (restclient-http-send-current-stay-in-window))))
  
      ;; (add-to-list 'load-path (concat plugin-home-dir "keyfreq"))
      ;; (require 'keyfreq)
      ;; (keyfreq-mode 1)
      ;;(keyfreq-autosave-mode 1)
  
      (add-to-list 'load-path (concat plugin-home-dir "rainbow-delimiters-20210515.1254"))
      (require 'rainbow-delimiters)
      (rainbow-delimiters-mode t)
  
  
      (add-to-list 'load-path (concat plugin-home-dir "powerline-20221110.1956"))
      (require 'powerline)
      (powerline-default-theme)
  
  
      (add-to-list 'load-path (concat plugin-home-dir "window-numbering"))
      (require 'window-numbering)
      (window-numbering-mode t)
      (size-indication-mode t)
  
      (add-to-list 'load-path (concat plugin-home-dir "anzu"))
      (require 'anzu)
      (global-anzu-mode +1)
      (set-face-attribute 'anzu-mode-line nil
                      :foreground "yellow" :weight 'bold)
  
      (custom-set-variables
       '(anzu-mode-lighter "")
       '(anzu-deactivate-region t)
       '(anzu-search-threshold 1000)
       '(anzu-replace-threshold 50)
       '(anzu-replace-to-string-separator " => "))

      (define-key isearch-mode-map [remap isearch-query-replace]  #'anzu-isearch-query-replace)
      (define-key isearch-mode-map [remap isearch-query-replace-regexp] #'anzu-isearch-query-replace-regexp)
)


  
  
(global-set-key [M-left] 'windmove-left)          ; move to left window
(global-set-key [M-right] 'windmove-right)        ; move to right window
(global-set-key [M-up] 'windmove-up)              ; move to upper window
(global-set-key [M-down] 'windmove-down)          ; move to lower window

(with-eval-after-load 'popwin
  (setq rustic-compile-display-method 'pop-to-buffer)
  (add-to-list 'popwin:special-display-config '(rustic-compilation-mode :noselect t)))


(setq user-full-name "frank"
      user-mail-address "frank@gmail.com")

(setq evil-snipe-override-evil-repeat-keys nil)


;; If you use `org' and don't want your org files in the default location below,
;; change `org-directory'. It must be set before org loads!
(setq org-directory "~/org/")

;; This determines the style of line numbers in effect. If set to `nil', line
;; numbers are disabled. For relative line numbers, set this to `relative'.
(setq display-line-numbers-type t)


;; emacs 内置功能配置
;; enable fill-column-indicator (since emacs 27.1) in prog mode
;; see https://www.gnu.org/software/emacs/manual/html_node/emacs/Displaying-Boundaries.html
;;(add-hook 'prog-mode-hook (lambda ()
;;        (setq fill-column 120)
;;        (setq display-fill-column-indicator t)
;;        (setq display-fill-column-indicator-column t)
;;        ;; (display-fill-column-indicator-mode)
;;        (global-display-fill-column-indicator-mode)
;;))


;;accelerate menu pop up
(setq which-key-idle-delay 0.1)

;;search chinese language utf8
;;search in project:SPC-/
(setq-default default-process-coding-system `(utf-8-dos . ,locale-coding-system))

(prefer-coding-system 'utf-8)
(set-default-coding-systems 'utf-8)
(set-terminal-coding-system 'utf-8)
(set-keyboard-coding-system 'utf-8)
;; backwards compatibility as default-buffer-file-coding-system
;; is deprecated in 23.2.
(if (boundp 'buffer-file-coding-system)
(setq-default buffer-file-coding-system 'utf-8)
(setq default-buffer-file-coding-system 'utf-8))

;; Treat clipboard input as UTF-8 string first; compound text next, etc.
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))


;;python
(org-babel-do-load-languages
 'org-babel-load-languages
 '((python . t)))


;;elisp
(defun eval-this-buffer ()
  (interactive)
  (eval-buffer nil (get-buffer-create "output"))
  (switch-to-buffer-other-window "output"))



;;mode-line
(defun graphic-powerline-config ()
  "powerline setting for graphic"
  (interactive)
  (progn
   (setq powerline-arrow-shape 'arrow)
   (custom-set-faces
    '(mode-line ((t (:foreground "white" :background "#0044cc" :height 100 :family "YaHei Mono" :height 90 :box nil))))
    '(mode-line-inactive ((t (:foreground "white" :background "#4682B4" :height 100 :family "YaHei Mono" :height 90 :box nil))))
    )
   (setq powerline-color1 "#0088cc")
   (setq powerline-color2 "white")
   )
  )

(defun terminal-powerline-config()
   " powerline setting for terminal"
   (interactive)
   (setq powerline-arrow-shape 'arrow)
   (setq powerline-color1 "grey22")
   (setq powerline-color2 "grey22") 
   (custom-set-faces
    '(mode-line ((t (:foreground "grey44" :background "grey22" :box nil))))
    '(mode-line-inactive ((t (:foreground "grey22" :background "grey44" :box nil))))
    ))

(if (display-graphic-p)
    (graphic-powerline-config)
    (terminal-powerline-config))


(put 'dired-find-alternate-file 'disabled nil)



(defun toggle-maximize-buffer ()
  "Maximize buffer"
  (interactive)
  (save-excursion
    (if (and (= 1 (length (cl-remove-if
                           (lambda (window)
                             (window-parameter window 'no-delete-other-windows))
;;  (if (and (= 1 (length (window-list)))
                           (window-list))))
             (assoc ?_ register-alist))
        (jump-to-register ?_)
      (progn
        (window-configuration-to-register ?_)
        (delete-other-windows)))))




(setq ffip-use-rust-fd t)
;;(when (eq system-type 'windows-nt) (setq ffip-find-executable (concat (getenv "HOME") "\\\\home\\\\emacs-28.2\\\\bin\\\\fd.exe")))
;;(when (eq system-type 'windows-nt) (setq ffip-find-executable "d:\\\\home\\\\emacs-28.2\\\\bin\\\\fd.exe"))



(defun my/project-try-local (dir)
  "Determine if DIR is a non-Git project."
  (catch 'ret
    (let ((pr-flags '((".project")
                      ("go.mod" "Cargo.toml" "project.clj" "pom.xml" "package.json"))))
      (dolist (current-level pr-flags)
        (dolist (f current-level)
          (when-let ((root (locate-dominating-file dir f)))
            (throw 'ret (cons 'local root))))))))
(setq project-find-functions '(my/project-try-local project-try-vc))



(defun my/project-files-in-directory (dir)
  "Use `fd' to list files in DIR."
  (let* ((default-directory dir)
         (localdir (file-local-name (expand-file-name dir)))
         (command (format "fd -H -t f -0 . %s" localdir)))
    (project--remote-file-names
     (sort (split-string (shell-command-to-string command) "\0" t)
           #'string<))))

(cl-defmethod project-files ((project (head local)) &optional dirs)
  "Override `project-files' to use `fd' in local projects."
  (mapcan #'my/project-files-in-directory
          (or dirs (list (project-root project)))))



(defun my/project-info ()
  (interactive)
  (message "%s" (project-current t)))

(defun my/add-dot-project ()
  (interactive)
  (let* ((root-dir (read-directory-name "Root: "))
         (f (expand-file-name ".project" root-dir)))
    (message "Create %s..." f)
    (make-empty-file f)))

(defun my/project-discover ()
  "Add dir under search-path to project."
  (interactive)
  (dolist (search-path '("~/code/" "~/git/"))
    (dolist (file (file-name-all-completions  "" search-path))
      (when (not (member file '("./" "../")))
        (let ((full-name (expand-file-name file search-path)))
          (when (file-directory-p full-name)
            (when-let ((pr (project-current nil full-name)))
              (project-remember-project pr)
              (message "add project %s..." pr))))))))



;;window-status
(defun emacs-maximize ()  
  "Maximize emacs window in windows os"  
  (interactive)  
  (w32-send-sys-command 61488))        ; WM_SYSCOMMAND #xf030 maximize  
(defun emacs-minimize ()  
  "Minimize emacs window in windows os"  
  (interactive)  
  (w32-send-sys-command #xf020))    ; #xf020 minimize  
(defun emacs-normal ()  
  "Normal emacs window in windows os"  
  (interactive)  
  (w32-send-sys-command #xf120))    ; #xf120 normalimize  
(global-set-key (kbd  "M-RET") 'emacs-maximize)
(global-set-key (kbd  "M-n") 'emacs-normal)


(defun f-normal-buffer ()
  (or (not buffer-read-only)
      (buffer-file-name)))

(defun c-switch-to-next-buffer ()
  (interactive)
  (unless (minibufferp)
    (let ((p t) (bn (buffer-name)))
      (switch-to-next-buffer)
      (while (and p (not (f-normal-buffer)))
	(switch-to-next-buffer)
	(when (string= bn (buffer-name)) (setq p nil))))))

(defun c-switch-to-prev-buffer ()
  (interactive)
  (unless (minibufferp)
    (let ((p t) (bn (buffer-name)))
      (switch-to-prev-buffer)
      (while (and p (not (f-normal-buffer)))
	(switch-to-prev-buffer)
	(when (string= bn (buffer-name)) (setq p nil))))))


;;compile
;;(global-set-key (kbd "M-<f7>") 'compile)
;;(global-set-key [f7] 'compile)


(global-set-key (kbd "C-c y") 'clipboard-yank) ;;
(global-set-key (kbd "C-M-q") 'query-replace)
(global-set-key (kbd "<f5>") 'flyspell-mode)
(global-set-key (kbd "C-<f5>") 'linum-mode)
(global-set-key (kbd "C-<right>") 'forward-sentence)

(add-hook 'c++-mode-hook
  (lambda ()
    (local-set-key (kbd "M-<f7>") 'compile)
  )
)

(add-hook 'lisp-mode-hook
  (lambda ()
    (local-set-key (kbd "M-<f7>") 'eval-this-buffer)
  )
)

(defun my-org-func ()
  (interactive)
  (message "hello, org!"))
(define-key org-mode-map (kbd "C-c d") 'my-org-func)

(define-key yas-minor-mode-map [(tab)]        nil)
(define-key yas-minor-mode-map (kbd "TAB")    nil)
(define-key yas-minor-mode-map (kbd "<tab>")  nil)
(define-key yas-minor-mode-map (kbd "M-c") 'yas-expand-from-trigger-key)


(global-set-key (kbd "C-/") 'citre-peek)
(global-set-key (kbd "M-]") 'citre-jump)
(global-set-key (kbd "M-[") 'citre-jump-back)
(global-set-key (kbd "M-m") 'citre-update-this-tags-file)

(defun uuid-insert()
  (interactive)
  (require 'uuid)
  (insert (upcase (uuid-string)))
)

(defun new-line ()
  (interactive)
  (end-of-line)
  (newline-and-indent))


(evil-set-register ?u [?  ?u ?u ?i ?d ?  ?n ?e ?w ?l ?i ?n ?e])
(evil-set-register ?p [?i ?\( ?\) escape ?i ?p ?r ?i ?n ?t ?  ?\( ?\) escape ?i ?m ?d ?5 ?  ?\" ?\" escape ?i ?h ?e ?l ?l ?o ?  ?w ?o ?r ?l ?d escape ?$ ?a return escape])


;;(global-set-key (kbd "<f8>") (lambda () (interactive) (insert "→")))
;;(define-key key-translation-map (kbd "<f8>") (kbd "•")) 
;;(global-set-key '[8711] 'Control-X-prefix)
;;vil-force-normal-state
;(define-key key-translation-map (kbd "[8711]") (kbd "<escape>"))


;; bash
(setenv "BASH_ENV" "~/.bashrc")
(setq process-connection-type "t")
;(setq shell-file-name (executable-find "bash"))
;(setq shell-delimiter-argument-list "--login" "-i")
;;(setq shell-command-switch "-ic")
(setq explicit-shell-file-name "c:/git/bin/bash.exe")
(setq explicit-bash-args '("--login" "-i"))
(setq shell-command-switch "-c")

;;M-f
(global-set-key (kbd "M-f") 'switch-to-buffer)



(setq day-theme-list '(adwaita dlichromacy light-blue tango))
(setq dark-theme-list '(dracula darkokai deeper-blue manoj-dark tango-dark wheatgrass tango-dark tsdh-dark wombat modus-vivendi))

(defun my-random-element (my-list)
  "Return a random element from MY-LIST."
  (let ((my-length (length my-list))
	   (my-random-index (random (length my-list))))
	   (nth my-random-index my-list)
  )
)

(defun synchronize-theme ()
  (setq hour (string-to-number (substring (current-time-string) 11 13)))
  (if (member hour (number-sequence 8 9))
	  (progn
		(setq now (my-random-element day-theme-list))
		(setq lst (my-random-element dark-theme-list))
          )
    (setq now (my-random-element dark-theme-list))
    (setq lst (my-random-element dark-theme-list))
  )
  (mapc 'disable-theme custom-enabled-themes)
  (load-theme now t)
)

(let* ((current-minutes (string-to-number (substring (current-time-string) 14 16)))
	   (current-seconds (string-to-number (substring (current-time-string) 17 20)))
	   (remain-seconds (- 3600 (* 60 current-minutes) current-seconds))
      )
  (run-with-timer remain-seconds 3600 'synchronize-theme)
)

(defun move-middle-of-line ()
  (interactive)
  (end-of-line)
  (backward-char (/ (current-column) 2)))

    
(display-time-mode 1) ;; 常显
(setq display-time-24hr-format t) ;;格式
(setq display-time-day-and-date t) ;;显示时间、星期、日期
(setq inhibit-startup-message t)
;(global-hl-line-mode 1)    
(column-number-mode t)
(show-paren-mode t)
(tool-bar-mode 0)
(menu-bar-mode 0)
(scroll-bar-mode 0)
(recentf-mode t)
(setq recentf-max-menu-items 20)
(setq default-cursor-type 'bar)
(cua-mode t)
;;设置缩进
(setq indent-tabs-mode t)
(setq default-tab-width 4)
(setq tab-width 4)
  


;(setq default-frame-alist'(
;    (vertical-scroll-bars)
;    (top . 0)
;    (right . 900)
;    (width . 1000)
;    (height . 600)
;    (background-color . "black")
;    (foreground-color . "grey")
;    (cursor-color . "gold1")
;    (mouse-color . "gold1")
;    (tool-bar-lines . 0)
;    (menu-bar-lines . 0)
;  )
;)
;(set-frame-parameter (car (frame-list)) 'undecorated t)

;(global-set-key (kbd "C-z") 'evil-local-mode)
;max window after startup
;(add-to-list 'default-frame-alist '(fullscreen . maximized))


(setq frame-title-format
    '(:eval
	(concat
            (if (and buffer-file-name (buffer-modified-p)) "•")
            (buffer-name)
            (if buffer-file-name (concat " (" (directory-file-name (abbreviate-file-name default-directory)) ")"))
        )
    )
)


(defun show-file-name ()
  "Show the full path file name in the minibuffer."
  (interactive)
  (let ((name (buffer-file-name)))
    (kill-new name)
    (message name)))


(setq-default header-line-format '(" %l %b " default-directory))
;(set-frame-parameter (car (frame-list)) 'undecorated t)
(global-set-key (kbd "C-}") 'enlarge-window)
(global-set-key (kbd "C-{") 'shrink-window)
(global-set-key (kbd "C->") 'other-window)
(fset 'yes-or-no-p 'y-or-n-p)
(setq track-eol t)
(setq scroll-step 1 scroll-margin 3 scroll-conservatively 10000)
(setq auto-image-file-mode t)
(setq transient-mark-mode t)
(setq auto-fill-mode t)



(put 'erase-buffer 'disabled nil)


(defun cls()
  "to clear the eshell buffer"
  (interactive)
  (let ((inhibit-read-only t))
    (erase-buffer)))
